package com.teamTPZoo.Util;

import org.apache.log4j.Logger;

public class Filters {
    private        Logger   logger          = Logger.getLogger(Filters.class);

    public  static String[] XSSSource       = { "<"    , ">"    , "\""   , "\'"   , "/"     };
    public  static String[] XSSTarget       = { "&#60;", "&#62;", "&#34;", "&#39;", "&#47;" };
    
    public  static String[] InjectionSource = { "&"    , "<"    , ">"    , "\""   , "\'"    };
    public  static String[] InjectionTarget = { "&amp;", "&lt;" , "&gt;" , "&#34;", "&#39;" };

    
    public String inXSS( String src )
    {
        if( (src != null) && (src.length() > 0) ) {
            for (int i = 0, forsize = XSSSource.length; i < forsize; i++) {
            	src = src.replaceAll(XSSSource[i], XSSTarget[i]);
            }
        }

        return src;
    }
	
    public String outXSS( String src )
    {
        if( (src != null) && (src.length() > 0) ) {
            for (int i = 0, forsize = XSSSource.length; i < forsize; i++) {
            	src = src.replaceAll(XSSTarget[i], XSSSource[i]);
            }
        }

        return src;
    }
    
	public static String inInjection( String src ) 
	{
        if( (src != null) && (src.length() > 0) ) {
            for (int i = 0, forsize = InjectionSource.length; i < forsize; i++) {
            	src = src.replaceAll(InjectionSource[i], InjectionTarget[i]);
            }
        }

        return src;
	}
	
	public static String outInjection( String src ) 
	{
        if( (src != null) && (src.length() > 0) ) {
            for (int i = 0, forsize = InjectionSource.length; i < forsize; i++) {
            	src = src.replaceAll(InjectionTarget[i], InjectionSource[i]);
            }
        }

        return src;
	}
}
